// 防抖  - 防止重复点击
export function _debounce (fn, delay) {
  delay = delay || 200;
  let timer;
  return function () {
    let _this = this;
    let args = arguments;
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(function () {
      timer = null;
      fn.apply(_this, args);
    }, delay);
  };
}
// 节流 - 防止重复上拉加载
export function _throttle (fn, interval) {
  let last;
  let timer;
  interval = interval || 200;
  return function () {
    let _this = this;
    let args = arguments;
    let now = +new Date();
    if (last && now - last < interval) {
      clearTimeout(timer);
      timer = setTimeout(function () {
        last = now;
        fn.apply(_this, args);
      }, interval);
    } else {
      last = now;
      fn.apply(_this, args);
    }
  };
}
